<template>
  <div class="mod-marketing-coupon">
    <div class="search-bar">
      <el-form :inline="true" class="search-form" ref="searchForm" :model="searchForm" size="small" >
        <div class="input-row">
          <el-form-item prop="reportSou" label="被举报源: " label-width="70px" class="search-form-item">
            <el-select v-model="searchForm.reportSou" placeholder="选择被举报源">
              <el-option label="广场" :value="0"></el-option>
              <el-option label="圈子" :value="1"></el-option>
              <el-option label="聊天" :value="2"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="reportType" label="举报类型: " label-width="70px" class="search-form-item">
            <el-select v-model="searchForm.reportType" placeholder="选择举报类型">
              <el-option label="原文" :value="0"></el-option>
              <el-option label="评论" :value="1"></el-option>
              <el-option label="单聊" :value="2"></el-option>
              <el-option label="群聊" :value="3"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="status" :label="$t('chain.status') + ':'" label-width="60px" class="search-form-item">
            <el-select v-model="searchForm.status" :placeholder="$t('chain.status')">
              <el-option label="待处理" :value="0"></el-option>
              <el-option label="已处理" :value="1"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item prop="titleId" :label="$t('chain.status') + ':'" label-width="60px" class="search-form-item">
            <el-select v-model="searchForm.titleId" placeholder="举报原因">
              <el-option
                v-for="item in titleList"
                :key="item.id"
                :label="item.title"
                :value="item.id"
              ></el-option>
            </el-select>
          </el-form-item>

          <div class="default-btn primary-btn marginBottom" @click="searchChange()">{{$t('product.search')}}</div>
          <div class="default-btn" @click="resetSearchForm('searchForm')">{{$t('product.reset')}}</div>
        </div>
      </el-form>
    </div>
    <div class="main-container">
      <div class="table-con coupon-table">
        <el-table
          ref="couponListTable"
          :data="dataList"
          header-cell-class-name="table-header"
          row-class-name="table-row-low"
          style="width: 100%">

          <el-table-column
            prop="reportSou"
            label="被举报源"
            width="80">
            <template slot-scope="scope">
              <span v-if="scope.row.reportSou === 0" class="tag-text">广场</span>
              <span v-else-if="scope.row.reportSou === 1" class="tag-text">圈子</span>
              <span v-else-if="scope.row.reportSou === 2" class="tag-text">聊天</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="reportType"
            label="举报类型"
            width="80">
            <template slot-scope="scope">
              <span v-if="scope.row.reportType === 0" class="tag-text">原文</span>
              <span v-else-if="scope.row.reportType === 1" class="tag-text">评论</span>
              <span v-else-if="scope.row.reportType === 2" class="tag-text">单聊</span>
              <span v-else-if="scope.row.reportType === 3" class="tag-text">群聊</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="reportContent"
            label="被举报内容"
            width="auto">
            <template slot-scope="scope">
              <a class="table-cell-text" @click="reportDetail(scope.row)" v-if="scope.row.reportSou === 2">{{scope.row.reportType == 3 ? '【' : ''}}{{scope.row.reportType == 3 ? scope.row.reportName : '聊天记录截图'}}{{scope.row.reportType == 3 ? '】群聊聊天记录截图' : ''}}</a>
              <a class="table-cell-text" @click="reportDetail(scope.row)" v-else>{{ scope.row.reportContent || '-' }}</a>
            </template>
          </el-table-column>
          <el-table-column
            prop="reportName"
            label="被举报方"
            width="150">
          </el-table-column>
          <el-table-column
            prop="title"
            label="举报原因"
            width="180">
          </el-table-column>
          <el-table-column
            prop="content"
            label="举报原因描述"
            width="auto">
            <template slot-scope="scope">
              <span class="table-cell-text">{{ scope.row.content || '-' }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="status"
            :label="$t('chain.status')"
            width="80">
            <template slot-scope="scope">
              <span v-if="scope.row.status === 0" class="tag-text">待处理</span>
              <span v-if="scope.row.status === 1" class="tag-text">已处理</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="opinion"
            label="处理意见"
            width="auto">
            <template slot-scope="scope">
              <span class="table-cell-text">{{ scope.row.opinion || '-' }}</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="nickName"
            label="举报用户"
            width="100">
          </el-table-column>
          <el-table-column
            prop="createTime"
            label="举报时间"
            width="150">
          </el-table-column>
          <el-table-column
            fixed="right"
            align="center"
            :label="$t('publics.operating')"
            width="160"
          >
            <template slot-scope="scope">
              <div class="text-btn-con">
                <div class="default-btn text-btn" v-if="scope.row.status === 0" @click="handleAudit(scope.row)">审查处理</div>
              </div>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        v-if="dataList.length"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="page.current"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="page.size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page.total">
      </el-pagination>
    </div>
    <!-- 弹窗, 处理 -->
    <el-dialog title="处理" :visible.sync="dialogAuditVisible" center width="30%" :close-on-click-modal="false" >
      <div style="display: flex;flex-direction: column;align-items: center;justify-content: center;">
        <el-input v-model="reason" placeholder="输入处理意见"  maxlength="70"  clearable></el-input>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogAuditVisible = false">取消</el-button>
        <el-button @click="audit(1)">确定</el-button>
        <el-button type="primary" @click="audit(2)">{{buttonName}}</el-button>
      </span>
    </el-dialog>

    <detail v-if="detailVisible"
                   ref="detail"
                   @refreshDataList="getDataList"></detail>

  </div>
</template>

<script>
  import Detail from './detail'

  export default {
    components: {
      Detail
    },
    data () {
      return {
        dialogAuditVisible: false,
        detailVisible: false,
        reason: '',
        auditData: null,
        dataForm: {
          name: '',
          code: '',
          status: null
        },
        dataList: [],
        dataListLoading: false,
        page: {
          total: 0, // 总页数
          current: 1, // 当前页数
          size: 10 // 每页显示多少条
        },
        titleList: [],
        buttonName: '违规下架',
        searchForm: {
          reportSou: '',
          reportType: '',
          status: '',
          titleId: ''
        }
      }
    },
    created () {
      this.getDataList()
      this.getTitleDataList()
    },
    methods: {
      reportDetail (row) {
        this.detailVisible = true
        this.$nextTick(() => {
          this.$refs.detail.init(row)
        })
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/admin/report/page'),
          method: 'get',
          params: this.$http.adornParams(
            Object.assign(
              this.page,
              this.searchForm
            ), false
          )
        }).then(({ data }) => {
          this.dataList = data.records
          this.page.total = data.total
          this.dataListLoading = false
        })
      },
      getTitleDataList () {
        this.$http({
          url: this.$http.adornUrl('/admin/report/title/list'),
          method: 'get',
          params: this.$http.adornParams()
        }).then(({ data }) => {
          this.titleList = data
        })
      },
      // 新增 / 修改
      handleAudit (row) {
        this.auditData = row
        if (row.reportSou == 2) {
          this.buttonName = row.reportType == 2 ? '封禁用户' : '解散群聊'
        } else {
          this.buttonName = '违规下架'
        }
        this.reason = ''
        this.dialogAuditVisible = true
      },
      audit: function (type) {
        if (!this.reason) {
          this.$message.error('请输处理意见')
          return
        }
        if (type == 2) {
          this.$confirm('确定做【' + this.buttonName + '】处理吗？', this.$i18n.t('text.tips'), {
            confirmButtonText: this.$i18n.t('coupon.confirm'),
            cancelButtonText: this.$i18n.t('coupon.cancel'),
            type: 'warning'
          }).then(() => {
            this.auditSubmit(type)
          }).catch(() => { })
        } else {
          this.auditSubmit(type)
        }
      },
      auditSubmit (type) {
        let param = {} // type = 1处理 2下架
        param.id = this.auditData.id
        param.status = type
        param.opinion = this.reason
        this.$http({
          url: this.$http.adornUrl('/admin/report/audit'),
          method: 'post',
          data: this.$http.adornData(
            param)
        }).then(({ data }) => {
          this.dialogAuditVisible = false
          this.$message({
            message: this.$i18n.t('publics.operation'),
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.getDataList()
            }
          })
        })
      },
      // 条件查询
      searchChange () {
        this.page.total = 0
        this.page.current = 1
        this.getDataList()
      },
      // 刷新回调用
      refreshChange () {
        this.page.total = 0
        this.page.current = 1
        this.page.size = 10
        this.getDataList(this.page)
      },
      /**
       * 重置表单
       * @param {String} formName 表单名称
       */
      resetSearchForm (formName) {
        this.$refs[formName].resetFields()
        this.refreshChange()
      },
      handleSizeChange (val) {
        this.page.size = val
        this.getDataList()
      },
      handleCurrentChange (val) {
        this.page.current = val
        this.getDataList()
      },

    }
  }
</script>
<style lang="scss" scoped>
  .marginBottom{margin-bottom:20px}
</style>
